import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Brand } from './brandschema'
import { Model } from 'mongoose'

@Injectable()
export class BrandService {

    // 模型注入
    constructor(@InjectModel(Brand.name) private BrandSchema: Model<Brand>) {
    }
    //添加品牌
    async addBrand(body: any) {
        
        await this.BrandSchema.create(body)
        return "添加成功" 
    }
    //查询品牌
    async getBrand(searchList:any[]) {
        let data
        if (searchList.length > 0) {
            data = await this.BrandSchema.find({ $and: searchList }) // 使用

        } else {
            data = await this.BrandSchema.find() // 使用
        }

        return data
    } 
    //修改品牌  
    async updateBrand(body: any) {
        await this.BrandSchema.updateOne({ _id: body._id }, body)
        return  "修改成功"
    }
    //删除品牌
    async deleteBrand(body: any) {
        await this.BrandSchema.deleteOne({ _id: body._id })
        return "删除成功"
    }

    
}